package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@HttpInlet(Conn.INLET_SET_NEW_INS_ORDER)
public class SetInsOrder extends JTAsyGet<SetInsOrder.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String UserId = JTApplication.jtPreferences.readUserID();

    public String ObdId = JTApplication.jtPreferences.readOdbID();

    public String companyId;

    public String OwnerName;

    public String phone;

    public String IdCard;

    public String address;

    public String Platenumber;

    public String Vin;

    public String engine;

    public String pp;

    public String xh;

    public String pl;

    public String bs;

    public String year;

    public String yearLimit;

    public String qx;

    public String sx;

    public String qxDate;

    public String sxDate;

    public String typeList;

    public String numList;

    public String flagList;

    public String flag;


    public SetInsOrder( AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.code = head.optString("code");

        JSONObject body = apiTYF.optJSONObject("body");

        info.flag = body.optString("flag");

        info.sxId = body.optString("sxId");

        info.qxId = body.optString("qxId");
        if(!info.qxId.equals("")){

            info.qxCCS = body.optString("qxCCS");

            info.qxJQX = body.optString("qxJQX");

        }

        BaoxianOrder baoxianOrder = new BaoxianOrder();

        JSONObject Orderobject = body.optJSONArray("sxOrder").optJSONObject(0);

        baoxianOrder.PHONE = Orderobject.optString("phone");

        baoxianOrder.ACCEPT_ADDRESS = Orderobject.optString("acceptAddress");

        baoxianOrder.CAR_VERSIONS = Orderobject.optString("carVersions");

        baoxianOrder.OWNER_NAME = Orderobject.optString("ownerName");

        baoxianOrder.CAR_XH = Orderobject.optString("carXh");

        baoxianOrder.VIN = Orderobject.optString("vin");

        baoxianOrder.CAR_BAND = Orderobject.optString("carBand");

        baoxianOrder.YEAR = Orderobject.optString("year");

        baoxianOrder.YEAR_LIMIT = Orderobject.optString("yearLimit");

        baoxianOrder.ENGINE = Orderobject.optString("engine");

        baoxianOrder.IDCARD = Orderobject.optString("idcard");

        baoxianOrder.ENGINE_SIZE = Orderobject.optString("engineSize");

        baoxianOrder.PLATE_NUM = Orderobject.optString("platenumber");



        info.baoxianOrder = baoxianOrder;

        if(!info.sxId.equals("")){

            JSONArray Vcilist = body.optJSONArray("sxList");
            if (Vcilist != null) {
                for (int i = 0; i < Vcilist.length(); i++) {
                    JSONObject object_vci = Vcilist.optJSONObject(i);
                    VCIList vciList = new VCIList();
                    vciList.NAME = object_vci.optString("NAME");
                    vciList.INSURANCE_TYPE = object_vci.optString("INSURANCE_TYPE");
                    vciList.NUM = object_vci.optString("NUM");
                    vciList.FLAG = object_vci.optString("FLAG");
                    vciList.BAOE = object_vci.optString("BAOE");
                    info.vciList.add(vciList);
                }
            }

        }

        return info;
    }

    public static class Info implements Serializable {
        public String msg;
        public String code;
        public String qxId;
        public String sxId;
        public String qxCCS;
        public String qxJQX;
        public String flag;
        public BaoxianOrder baoxianOrder;
        public List<VCIList> vciList = new ArrayList<>();

    }

    public static class VCIList implements Serializable {
        public String NAME, INSURANCE_TYPE, NUM, FLAG, BAOE;
    }

    public static class BaoxianOrder implements Serializable{
        public String  PHONE,ACCEPT_ADDRESS,CAR_VERSIONS,OWNER_NAME,CAR_XH,VIN,CAR_BAND,YEAR,YEAR_LIMIT,ENGINE,IDCARD,ENGINE_SIZE,PLATE_NUM;

    }
}
